//
//    LoanInformation.swift
//
//    Create by 徐挺 陈 on 28/3/2018
//    Copyright © 2018. All rights reserved.
//    Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport

import Foundation
import SwiftyJSON
import PromiseKit


class LoanInformation: NSObject, NSCoding {
    
    var allPercent : Int!
    var cardPercent : Int!
    var contactPercent : Int!
    var otherInfo : OtherInfo!
    var otherInfoPercent : Int!
    var personalPercent : Int!
    var userCards : UserCard!
    var userContactInfo : [UserContactInfo]!
    var userPersonalInfo : UserPersonalInfo!
    var userWorkingInfo : UserWorkingInfo!
    var workingPercent : Int!
    
    
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!){
        if json.isEmpty{
            return
        }
        allPercent = json["allPercent"].intValue
        cardPercent = json["cardPercent"].intValue
        contactPercent = json["contactPercent"].intValue
        let otherInfoJson = json["otherInfo"]
        if !otherInfoJson.isEmpty{
            otherInfo = OtherInfo(fromJson: otherInfoJson)
        }
        otherInfoPercent = json["otherInfoPercent"].intValue
        personalPercent = json["personalPercent"].intValue
        let userCardsJson = json["userCards"]
        if !userCardsJson.isEmpty{
            userCards = UserCard(fromJson: userCardsJson)
        }
        userContactInfo = [UserContactInfo]()
        let userContactInfoArray = json["userContactInfo"].arrayValue
        for userContactInfoJson in userContactInfoArray{
            let value = UserContactInfo(fromJson: userContactInfoJson)
            userContactInfo.append(value)
        }
        let userPersonalInfoJson = json["userPersonalInfo"]
        if !userPersonalInfoJson.isEmpty{
            userPersonalInfo = UserPersonalInfo(fromJson: userPersonalInfoJson)
        }
        let userWorkingInfoJson = json["userWorkingInfo"]
        if !userWorkingInfoJson.isEmpty{
            userWorkingInfo = UserWorkingInfo(fromJson: userWorkingInfoJson)
        }
        workingPercent = json["workingPercent"].intValue
    }
    
    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String:Any]
    {
        var dictionary = [String:Any]()
        if allPercent != nil{
            dictionary["allPercent"] = allPercent
        }
        if cardPercent != nil{
            dictionary["cardPercent"] = cardPercent
        }
        if contactPercent != nil{
            dictionary["contactPercent"] = contactPercent
        }
        if otherInfo != nil{
            dictionary["otherInfo"] = otherInfo.toDictionary()
        }
        if otherInfoPercent != nil{
            dictionary["otherInfoPercent"] = otherInfoPercent
        }
        if personalPercent != nil{
            dictionary["personalPercent"] = personalPercent
        }
        if userCards != nil{
            dictionary["userCards"] = userCards.toDictionary()
        }
        if userContactInfo != nil{
            var dictionaryElements = [[String:Any]]()
            for userContactInfoElement in userContactInfo {
                dictionaryElements.append(userContactInfoElement.toDictionary())
            }
            dictionary["userContactInfo"] = dictionaryElements
        }
        if userPersonalInfo != nil{
            dictionary["userPersonalInfo"] = userPersonalInfo.toDictionary()
        }
        if userWorkingInfo != nil{
            dictionary["userWorkingInfo"] = userWorkingInfo.toDictionary()
        }
        if workingPercent != nil{
            dictionary["workingPercent"] = workingPercent
        }
        return dictionary
    }
    
    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        allPercent = aDecoder.decodeObject(forKey: "allPercent") as? Int
        cardPercent = aDecoder.decodeObject(forKey: "cardPercent") as? Int
        contactPercent = aDecoder.decodeObject(forKey: "contactPercent") as? Int
        otherInfo = aDecoder.decodeObject(forKey: "otherInfo") as? OtherInfo
        otherInfoPercent = aDecoder.decodeObject(forKey: "otherInfoPercent") as? Int
        personalPercent = aDecoder.decodeObject(forKey: "personalPercent") as? Int
        userCards = aDecoder.decodeObject(forKey: "userCards") as? UserCard
        userContactInfo = aDecoder.decodeObject(forKey: "userContactInfo") as? [UserContactInfo]
        userPersonalInfo = aDecoder.decodeObject(forKey: "userPersonalInfo") as? UserPersonalInfo
        userWorkingInfo = aDecoder.decodeObject(forKey: "userWorkingInfo") as? UserWorkingInfo
        workingPercent = aDecoder.decodeObject(forKey: "workingPercent") as? Int
        
    }
    
    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if allPercent != nil{
            aCoder.encode(allPercent, forKey: "allPercent")
        }
        if cardPercent != nil{
            aCoder.encode(cardPercent, forKey: "cardPercent")
        }
        if contactPercent != nil{
            aCoder.encode(contactPercent, forKey: "contactPercent")
        }
        if otherInfo != nil{
            aCoder.encode(otherInfo, forKey: "otherInfo")
        }
        if otherInfoPercent != nil{
            aCoder.encode(otherInfoPercent, forKey: "otherInfoPercent")
        }
        if personalPercent != nil{
            aCoder.encode(personalPercent, forKey: "personalPercent")
        }
        if userCards != nil{
            aCoder.encode(userCards, forKey: "userCards")
        }
        if userContactInfo != nil{
            aCoder.encode(userContactInfo, forKey: "userContactInfo")
        }
        if userPersonalInfo != nil{
            aCoder.encode(userPersonalInfo, forKey: "userPersonalInfo")
        }
        if userWorkingInfo != nil{
            aCoder.encode(userWorkingInfo, forKey: "userWorkingInfo")
        }
        if workingPercent != nil{
            aCoder.encode(workingPercent, forKey: "workingPercent")
        }
        
    }
    
}

class UserWorkingInfo: NSObject, NSCoding {

    var address: String!
    var companyCity: Int!
    var companyDistrics: Int!
    var companyDistricts: Int!
    var companyName: String!
    var companyPhone: String!
    var companyProvince: Int!
    var monthIncome: Int!
    var typeOfWork: String!
    var userId: Int!


    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!) {
        if json.isEmpty {
            return
        }
        address = json["address"].stringValue
        companyCity = json["companyCity"].intValue
        companyDistrics = json["companyDistrics"].intValue
        companyDistricts = json["companyDistricts"].intValue
        companyName = json["companyName"].stringValue
        companyPhone = json["companyPhone"].stringValue
        companyProvince = json["companyProvince"].intValue
        monthIncome = json["monthIncome"].intValue
        typeOfWork = json["typeOfWork"].stringValue
        userId = json["userId"].intValue
    }

    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String: Any]
    {
        var dictionary = [String: Any]()
        if address != nil {
            dictionary["address"] = address
        }
        if companyCity != nil {
            dictionary["companyCity"] = companyCity
        }
        if companyDistrics != nil {
            dictionary["companyDistrics"] = companyDistrics
        }
        if companyDistricts != nil {
            dictionary["companyDistricts"] = companyDistricts
        }
        if companyName != nil {
            dictionary["companyName"] = companyName
        }
        if companyPhone != nil {
            dictionary["companyPhone"] = companyPhone
        }
        if companyProvince != nil {
            dictionary["companyProvince"] = companyProvince
        }
        if monthIncome != nil {
            dictionary["monthIncome"] = monthIncome
        }
        if typeOfWork != nil {
            dictionary["typeOfWork"] = typeOfWork
        }
        if userId != nil {
            dictionary["userId"] = userId
        }
        return dictionary
    }

    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        address = aDecoder.decodeObject(forKey: "address") as? String
        companyCity = aDecoder.decodeObject(forKey: "companyCity") as? Int
        companyDistrics = aDecoder.decodeObject(forKey: "companyDistrics") as? Int
        companyDistricts = aDecoder.decodeObject(forKey: "companyDistricts") as? Int
        companyName = aDecoder.decodeObject(forKey: "companyName") as? String
        companyPhone = aDecoder.decodeObject(forKey: "companyPhone") as? String
        companyProvince = aDecoder.decodeObject(forKey: "companyProvince") as? Int
        monthIncome = aDecoder.decodeObject(forKey: "monthIncome") as? Int
        typeOfWork = aDecoder.decodeObject(forKey: "typeOfWork") as? String
        userId = aDecoder.decodeObject(forKey: "userId") as? Int

    }

    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if address != nil {
            aCoder.encode(address, forKey: "address")
        }
        if companyCity != nil {
            aCoder.encode(companyCity, forKey: "companyCity")
        }
        if companyDistrics != nil {
            aCoder.encode(companyDistrics, forKey: "companyDistrics")
        }
        if companyDistricts != nil {
            aCoder.encode(companyDistricts, forKey: "companyDistricts")
        }
        if companyName != nil {
            aCoder.encode(companyName, forKey: "companyName")
        }
        if companyPhone != nil {
            aCoder.encode(companyPhone, forKey: "companyPhone")
        }
        if companyProvince != nil {
            aCoder.encode(companyProvince, forKey: "companyProvince")
        }
        if monthIncome != nil {
            aCoder.encode(monthIncome, forKey: "monthIncome")
        }
        if typeOfWork != nil {
            aCoder.encode(typeOfWork, forKey: "typeOfWork")
        }
        if userId != nil {
            aCoder.encode(userId, forKey: "userId")
        }

    }
    
    func save() -> Promise<JSON> {
        let dic = self.toDictionary()
        let request = RequestData(path: "User/EditUserWorkingInfo", param: dic)
        return netRequest(request)
    }

}

class UserPersonalInfo: NSObject, NSCoding {

    var address: String!
    var education: Int!
    var fullName: String!
    var gender: Int!
    var idCard: String!
    var maritalStatus: Int!
    var motherName: String!
    var numberOfChildren: Int!
    var occupancyDuration: Int!
    var residentialCity: Int!
    var residentialDistrics: Int!
    var residentialDistricts: Int!
    var residentialProvince: String!
    var socialAccounts: String!
    var userId: Int!
    var userName: String!
    var birthday: String!


    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!) {
        if json.isEmpty {
            return
        }
        address = json["address"].stringValue
        education = json["education"].intValue
        fullName = json["fullName"].stringValue
        gender = json["gender"].intValue
        idCard = json["idCard"].stringValue
        maritalStatus = json["maritalStatus"].intValue
        motherName = json["motherName"].stringValue
        numberOfChildren = json["numberOfChildren"].intValue
        occupancyDuration = json["occupancyDuration"].intValue
        residentialCity = json["residentialCity"].intValue
        residentialDistrics = json["residentialDistrics"].intValue
        residentialDistricts = json["residentialDistricts"].intValue
        residentialProvince = json["residentialProvince"].stringValue
        socialAccounts = json["socialAccounts"].stringValue
        userId = json["userId"].intValue
        userName = json["userName"].stringValue
        birthday = json["birthday"].stringValue
    }

    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String: Any]
    {
        var dictionary = [String: Any]()
        if address != nil {
            dictionary["address"] = address
        }
        if education != nil {
            dictionary["education"] = education
        }
        if fullName != nil {
            dictionary["fullName"] = fullName
        }
        if gender != nil {
            dictionary["gender"] = gender
        }
        if idCard != nil {
            dictionary["idCard"] = idCard
        }
        if maritalStatus != nil {
            dictionary["maritalStatus"] = maritalStatus
        }
        if motherName != nil {
            dictionary["motherName"] = motherName
        }
        if numberOfChildren != nil {
            dictionary["numberOfChildren"] = numberOfChildren
        }
        if occupancyDuration != nil {
            dictionary["occupancyDuration"] = occupancyDuration
        }
        if residentialCity != nil {
            dictionary["residentialCity"] = residentialCity
        }
        if residentialDistrics != nil {
            dictionary["residentialDistrics"] = residentialDistrics
        }
        if residentialDistricts != nil {
            dictionary["residentialDistricts"] = residentialDistricts
        }
        if residentialProvince != nil {
            dictionary["residentialProvince"] = residentialProvince
        }
        if socialAccounts != nil {
            dictionary["socialAccounts"] = socialAccounts
        }
        if userId != nil {
            dictionary["userId"] = userId
        }
        if userName != nil {
            dictionary["userName"] = userName
        }
        if birthday != nil {
            dictionary["birthday"] = birthday
        }
        return dictionary
    }

    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        address = aDecoder.decodeObject(forKey: "address") as? String
        education = aDecoder.decodeObject(forKey: "education") as? Int
        fullName = aDecoder.decodeObject(forKey: "fullName") as? String
        gender = aDecoder.decodeObject(forKey: "gender") as? Int
        idCard = aDecoder.decodeObject(forKey: "idCard") as? String
        maritalStatus = aDecoder.decodeObject(forKey: "maritalStatus") as? Int
        motherName = aDecoder.decodeObject(forKey: "motherName") as? String
        numberOfChildren = aDecoder.decodeObject(forKey: "numberOfChildren") as? Int
        occupancyDuration = aDecoder.decodeObject(forKey: "occupancyDuration") as? Int
        residentialCity = aDecoder.decodeObject(forKey: "residentialCity") as? Int
        residentialDistrics = aDecoder.decodeObject(forKey: "residentialDistrics") as? Int
        residentialDistricts = aDecoder.decodeObject(forKey: "residentialDistricts") as? Int
        residentialProvince = aDecoder.decodeObject(forKey: "residentialProvince") as? String
        socialAccounts = aDecoder.decodeObject(forKey: "socialAccounts") as? String
        userId = aDecoder.decodeObject(forKey: "userId") as? Int
        userName = aDecoder.decodeObject(forKey: "userName") as? String
        birthday = aDecoder.decodeObject(forKey: "birthday") as? String

    }

    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if address != nil {
            aCoder.encode(address, forKey: "address")
        }
        if education != nil {
            aCoder.encode(education, forKey: "education")
        }
        if fullName != nil {
            aCoder.encode(fullName, forKey: "fullName")
        }
        if gender != nil {
            aCoder.encode(gender, forKey: "gender")
        }
        if idCard != nil {
            aCoder.encode(idCard, forKey: "idCard")
        }
        if maritalStatus != nil {
            aCoder.encode(maritalStatus, forKey: "maritalStatus")
        }
        if motherName != nil {
            aCoder.encode(motherName, forKey: "motherName")
        }
        if numberOfChildren != nil {
            aCoder.encode(numberOfChildren, forKey: "numberOfChildren")
        }
        if occupancyDuration != nil {
            aCoder.encode(occupancyDuration, forKey: "occupancyDuration")
        }
        if residentialCity != nil {
            aCoder.encode(residentialCity, forKey: "residentialCity")
        }
        if residentialDistrics != nil {
            aCoder.encode(residentialDistrics, forKey: "residentialDistrics")
        }
        if residentialDistricts != nil {
            aCoder.encode(residentialDistricts, forKey: "residentialDistricts")
        }
        if residentialProvince != nil {
            aCoder.encode(residentialProvince, forKey: "residentialProvince")
        }
        if socialAccounts != nil {
            aCoder.encode(socialAccounts, forKey: "socialAccounts")
        }
        if userId != nil {
            aCoder.encode(userId, forKey: "userId")
        }
        if userName != nil {
            aCoder.encode(userName, forKey: "userName")
        }
        if birthday != nil {
            aCoder.encode(birthday, forKey: "birthday")
        }

    }
    
    func save() -> Promise<JSON> {
        let dic = self.toDictionary()
        let request = RequestData(path: "User/EditUserPersonalInfo", param: dic)
        return netRequest(request)
    }
    

}

class UserContactInfo: NSObject, NSCoding {

    var address: String!
    var id: Int!
    var phone: String!
    var relationShip: Int!
    var relationUserName: String!
    var userId: Int!


    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!) {
        if json.isEmpty {
            return
        }
        address = json["address"].stringValue
        id = json["id"].intValue
        phone = json["phone"].stringValue
        relationShip = json["relationShip"].intValue
        relationUserName = json["relationUserName"].stringValue
        userId = json["userId"].intValue
    }

    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String: Any]
    {
        var dictionary = [String: Any]()
        if address != nil {
            dictionary["address"] = address
        }
        if id != nil {
            dictionary["id"] = id
        }
        if phone != nil {
            dictionary["phone"] = phone
        }
        if relationShip != nil {
            dictionary["relationShip"] = relationShip
        }
        if relationUserName != nil {
            dictionary["relationUserName"] = relationUserName
        }
        if userId != nil {
            dictionary["userId"] = userId
        }
        return dictionary
    }

    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        address = aDecoder.decodeObject(forKey: "address") as? String
        id = aDecoder.decodeObject(forKey: "id") as? Int
        phone = aDecoder.decodeObject(forKey: "phone") as? String
        relationShip = aDecoder.decodeObject(forKey: "relationShip") as? Int
        relationUserName = aDecoder.decodeObject(forKey: "relationUserName") as? String
        userId = aDecoder.decodeObject(forKey: "userId") as? Int

    }

    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if address != nil {
            aCoder.encode(address, forKey: "address")
        }
        if id != nil {
            aCoder.encode(id, forKey: "id")
        }
        if phone != nil {
            aCoder.encode(phone, forKey: "phone")
        }
        if relationShip != nil {
            aCoder.encode(relationShip, forKey: "relationShip")
        }
        if relationUserName != nil {
            aCoder.encode(relationUserName, forKey: "relationUserName")
        }
        if userId != nil {
            aCoder.encode(userId, forKey: "userId")
        }

    }
    
    func save() -> Promise<JSON> {
        let dic = self.toDictionary()
        let request = RequestData(path: "User/EditUserContactInfoV2", param: dic)
        return netRequest(request)
    }
}

class UserCard: NSObject, NSCoding {

    var idCardUrl: String!
    var workinfoCardUrl: String!


    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!) {
        if json.isEmpty {
            return
        }
        idCardUrl = json["IdCardUrl"].stringValue
        workinfoCardUrl = json["WorkinfoCardUrl"].stringValue
    }

    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String: Any]
    {
        var dictionary = [String: Any]()
        if idCardUrl != nil {
            dictionary["IdCardUrl"] = idCardUrl
        }
        if workinfoCardUrl != nil {
            dictionary["WorkinfoCardUrl"] = workinfoCardUrl
        }
        return dictionary
    }

    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        idCardUrl = aDecoder.decodeObject(forKey: "IdCardUrl") as? String
        workinfoCardUrl = aDecoder.decodeObject(forKey: "WorkinfoCardUrl") as? String

    }

    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if idCardUrl != nil {
            aCoder.encode(idCardUrl, forKey: "IdCardUrl")
        }
        if workinfoCardUrl != nil {
            aCoder.encode(workinfoCardUrl, forKey: "WorkinfoCardUrl")
        }

    }
    
    func save() -> Promise<[JSON]> {
        let dic_1 = [
            "type": "1",
            "url": idCardUrl!
        ];
        let dic_2 = [
            "type": "2",
            "url": workinfoCardUrl!
        ];
        let req_1 = RequestData(path: "User/EditUserPhotos", param: dic_1)
        let req_2 = RequestData(path: "User/EditUserPhotos", param: dic_2)
        return when(fulfilled: [netRequest(req_1), netRequest(req_2)])
    }

}

class OtherInfo : NSObject, NSCoding{
    
    var callLogNum : Int!
    var contactsNum : Int!
    var location : Int!
    
    
    /**
     * Instantiate the instance using the passed json values to set the properties values
     */
    init(fromJson json: JSON!){
        if json.isEmpty{
            return
        }
        callLogNum = json["CallLogNum"].intValue
        contactsNum = json["ContactsNum"].intValue
        location = json["Location"].intValue
    }
    
    /**
     * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property
     */
    func toDictionary() -> [String:Any]
    {
        var dictionary = [String:Any]()
        if callLogNum != nil{
            dictionary["CallLogNum"] = callLogNum
        }
        if contactsNum != nil{
            dictionary["ContactsNum"] = contactsNum
        }
        if location != nil{
            dictionary["Location"] = location
        }
        return dictionary
    }
    
    /**
     * NSCoding required initializer.
     * Fills the data from the passed decoder
     */
    @objc required init(coder aDecoder: NSCoder)
    {
        callLogNum = aDecoder.decodeObject(forKey: "CallLogNum") as? Int
        contactsNum = aDecoder.decodeObject(forKey: "ContactsNum") as? Int
        location = aDecoder.decodeObject(forKey: "Location") as? Int
        
    }
    
    /**
     * NSCoding required method.
     * Encodes mode properties into the decoder
     */
    func encode(with aCoder: NSCoder)
    {
        if callLogNum != nil{
            aCoder.encode(callLogNum, forKey: "CallLogNum")
        }
        if contactsNum != nil{
            aCoder.encode(contactsNum, forKey: "ContactsNum")
        }
        if location != nil{
            aCoder.encode(location, forKey: "Location")
        }
        
    }
    
}
